home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-11 | 9.1 KB | 167 lines | [TEXT/ttxt] |
- A Sample Device Driver
- for the New Device Driver Framework
-
- Martin Minow
- December 23, 1994 (in progress)
- ===========================================================================
-
- Introduction
- ~~~~~~~~~~
- This is a sample device driver that illustrates the new driver architecture that
- will become available with the Power Macintosh models that support PCI bus. The
- driver architecture will be used on future Macintosh operating system releases
- for Power PC and 68000 machines. The sample has the following characteristics:
- • Small: most of the code is “administrative” — almost all code that is
- specific to the particular hardware is isolated into a few subroutines.
- • Complete: the sample creates an asynchronous device driver that supports the
- NCR 8250 interface card that uses the NCR53C825 PCI bus interface.
- • Vendor-neutral: the driver and its framework may be compiled under
- MetroWerks Code Warrior 1.2 or MPW 3.3. An AppleScript facilitates building
- multiple instances. [The AppleScript is not implemented yet]. The framework
- runs under MetroWerks and MPW. It has not been built or tested under Think C,
- although this should not present difficulties. The test program has only been
- compiled by MetroWerks.
-
- Goals
- ~~~~~
- • A working device driver sample for the New Device Manager architecture that
- • illustrates asynchronous behavior and many of the new managers, and
- • follows the device driver model that will be used in future Macintosh systems.
-
- Non-Goals
- ~~~~~~~~
- • Concurrence: (i.e. capable of processing more than one simultaneous
- operations). This would require a great deal of NCR53C825-specific programming.
- • Full-scale: this driver illustrates the new driver architecture: it does
- not illustrate all capabilities of the new model.
- • This is not a SCSI sample.The board used was chosen as as a readily-available
- hardware sample. This driver should not be used as a basis for a SCSI device
- driver (or SIM). In particular, Apple recommends that SCSI devices be supported
- by device drivers communicating through the SCSI Manager, and that SCSI bus
- adaptors be supported by SIMS controlled by = SCSI Manager 4.3.
-
- The Sample Driver
- The driver allows an application program to issue SCSI commands directly to the NCR
- device. It does not support read/write or “drive” programming (i.e. it does not
- allow you to mount SCSI disks), but rather requires you to issue commands
- directly. In this regard, it functions somewhat like the SCSI Manager. In
- particular, it
- • Illustrates Primary Interrupt Service Routine processing.
- • Illustrates asynchronous I/O processing.
- • Illustrates DMA, direct read/write of device registers, and Expansion Bus
- Manager programming.
- • Illustrates System Registry processing.
-
- New Device Driver Architecture
- ~~~~~~~~~~~~~~~~~~~~~~~~~
- The Device Manager will be replaced beginning with the PCI machines. This new
- “native driver” architecture will be used for all new machines. While existing
- drivers will still work correctly, they cannot take advantage of Power Macintosh
- native code.
- Separation of function is central to the new architecture: drivers will not use
- Macintosh OS. services, and applications and non-driver code modules will not
- call the driver software library. This will mean significant changes for driver
- writers: parameters cannot be read from resource files, for example.
-
- The Three Aspects of a Device Driver
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- All device drivers contain three somewhat independent components:
- 1. The low-level bus interface or “hardware abstraction layer” that reads
- and modifies information in the external NuBus or PCI device.
- 2. A mid-level component that has the device driver’s task-specific
- intelligence. For example, this might contain disk driver buffering
- algorithms. This part is unique to each driver.
- 3. A high-level component that connects the Device Driver to the Macintosh
- operating system.
- Currently, Macintosh device drivers mix all three “levels” together, making
- them hard to write and harder to maintain. The new driver architecture makes it
- easier to abstract these layers. In particular, the operating system now handles
- the messy details of the high-level component within itself, presenting the
- device driver writer with a small library of interface functions.
- Another problem with the current device driver architecture is the reliance on
- specific features and quirks of the 68000 hardware and programming architecture.
- For example, critical sections are implemented by blocking hardware interrupts
- and drivers complete I/O requests by storing specific values into hardware
- registers and setting the 68000 condition codes. Drivers also need access to
- 68000 registers and system low-memory global values. The new architecture was
- designed to facilitate high-level language implementation. It provides a
- programming interface that is specific to device drivers and isolates them from
- the Macintosh Toolbox (i.e. device drivers may no longer display dialogs.)
-
- Converting Existing Device Drivers
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~
- For example, you may have developed a document scanner with an optical character
- recognition facility. The document scanner is controlled by a NuBus board that
- you designed, and you are building a PCI board to support the scanner on future
- Macintosh machines. In this model, the three aspects of the driver would be as
- follows:
- 1. The low-level bus interface manipulates registers on the NuBus. For the
- PCI system, this layer must be replaced with code that manipulates PCI
- registers. Also, a moderate amount of code will have to be written to
- support the PCI Device Registry.
- 2. The mid-level component in this example would include scanner management
- and, in particular, optical character recognition algorithms. These
- algorithms comprise the intelligence that sets your product apart from
- its competition.
- 3. The high-level component in your driver that interacts with the Device
- Manager can be thrown out and replaced with the considerably simpler
- “New Driver Architecture.” This is executed directly on PCI Macintosh
- systems.
-
- To convert your driver, you must do the following:
- • Isolate the functional components of your driver. For example, you may have
- an INIT, Notification Manager, Control Panel, parameter resources, and other
- software modules that will need re-thinking. For example, parameter
- resources will be replaced by data stored within the System Registry and
- manipulated by Open Firmware components. Drivers that need extensive
- parameterization should be loaded by INITs or applications that supply
- necessary data through private PBControl calls.
- • Rewrite your driver in very clean C code. Remove all 68000 assembly code and
- driver-specific inline functions.
- • Remove all references to the driver control block. Your driver’s private
- storage will be stored in global and static variables — and the Code
- Fragment Manager will handle initialization.
- • Replace all memory management (NewPtrSys) by Pool Allocation calls.
- • Add support for the Driver Gestalt PBStatus call.
- • Replace accRun support by with non-interrupt code that is available to the
- driver through calls provided by the Driver Service Library. In many cases,
- accRun functions can be provided through a faceless background application
- or INIT.
- • Control Panels and applications cannot access the driver code or its
- globals by using values in the DCE as this information is no longer visible
- to the driver. If necessary, you should create a set of accessor PBControl
- or PBStatus functions that manipulate your driver’s private values. The
- Driver Gestalt handler and the private debugging control and status handlers
- in the sample may be used as a model. While you could conceivably access
- driver variables by using the Code Fragment Manager (the driver would
- presumably export its variables), this should not be used for
- production drivers. Instead, I would recommend exporting driver global
- using a private PBStatus call as is done in the sample.
- • In the new framework, drivers are limited to a small subset of the existing
- operating system (the “System Programming Interface”). This will require
- some rethinking of many drivers. For example, they cannot load information
- from resources. The new architecture is not completely defined at this
- writing, and additional capabilities will likely become available.
- • If your driver may be used as a bootstrap device, plan for loading the
- full driver into the card's EEPROM and write an Open Firmware boot driver.
-
-
- C or C++
- ~~~~~~~
- C, of course. The only advantage of C++ is the ability to write an base class
- for DoDriverIO. Since the framework is only a few pages of code, this is a
- small advantage indeed. Writing in C++ brings with it the disadvantage of a
- much more difficult debugging situation, especially if you take advantage of
- its operator override, method override, and object creation capabilities. And,
- if you don’t, why bother in the first place.
- Write your driver in very clean, very clear C. Measure its performance (use
- the new nanosecond library), and hand-tune only those parts of the code that
- need tuning.
-
-
- Further Reference:
- ~~~~~~~~~~~~~~~
- • Inside Macintosh Devices.
- • Designing PCI Cards and Drivers for Power Macintosh Computers
-
-